<?php
namespace Application\Repository;
use Doctrine\ORM\EntityRepository;

class CityRepository extends AbstractRepository
{
    protected  $entity="Application\\Entity\\City";
    
    public function getByCountry($code)
    {
       $dql = "SELECT c FROM $this->entity c JOIN c.country u WHERE u.code=?1";
       
        $query= $this->getEntityManager()->createQuery($dql)
        ->setParameter(1, $code);
    
   
       return $query->getResult();
    }
    
    
    public function getByCountryProvince($code,$name)
    {
    	$dql = "SELECT c FROM $this->entity c WHERE c.province.name=?1 AND c.country.code=?2";
    
    	return $this->getEntityManager()->createQuery($dql)
    	->setParameter(1, $name)
    	->setParameter(2, $code)
    	->getResult();
    }
    
    public function getByNameCountryProvince($nameCity,$code,$name)
    {
    	$dql = "SELECT c FROM $this->entity c WHERE c.name=?1 AND c.province.name=?2 AND c.country.code=?3";
    
    	return $this->getEntityManager()->createQuery($dql)
    	->setParameter(1, $nameCity)
    	->setParameter(2, $name)
    	->setParameter(3, $code)
    	->getResult();
    }
}